var vote= new Vue({
    el : '#Votelist',
    data:{
        userId : $("#id").val(),
        xiangmuId:$("#xiangmuId").val(),
        xiangmuleixing:$("#xiangmuleixing").val(),

        drugname:'',
        jicaiyao:'',
        fenleilist:[],
        fenlei:'',
        jiyao:'',
        yizhipingjia:'',
        yuanze:'',

        xiangmu : {},
        votelist:[],
        show : false,
        total:0,
        tongyishu:0,
        butongyishu:0,

        pinzhongshu:0,
        pinguishu:0,
        jicaiyaoshu:0,
        fenleishu:0,
        shengyujicaiyaoshu:0,

        issubmited:false,
        isallsubmited:false,


        pageIndex : 1,
        pageSize :80,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",
    },
    created : function() {
        var _this = this;

        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");
        _this.findIsacticed();
        _this.getfenleilist();


    },
    methods : {

        findIsacticed:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid :_this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId=_this.xiangmu.xiangmuid;
                        _this.xiangmuleixing=_this.xiangmu.xiangmuleixing;
                        _this.checkIsSubmited();
                        _this.checkIsAllSubmited();
                        _this.getkangjunResultCount();

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        getfenleilist:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/kangjunyaowu/getfenleilist', {
                xiangmuid :_this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.fenleilist = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        remove:function (){
           this.drugname="";
           this.jicaiyao="";
           this.fenlei="";
           this.jiyao="";
           this.yizhipingjia="";
           this.yuanze="";
           this.findBiaojuelist();
        },


        toRefresh:function (){
            // this.checkIsSubmited();
            // this.checkIsAllSubmited();
            // this.getkangjunResultCount();
            location.reload();
        },

        findBiaojuelist:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/kangjunyaowu/findBiaojuelist",{
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,

                drugname :$.trim(_this.drugname),
                fenlei :_this.fenlei,
                jiyao:_this.jiyao,
                yizhipingjia:_this.yizhipingjia,
                yuanze:_this.yuanze,
                jicaiyao :_this.jicaiyao,

                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<div class='table-head'><table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            // "   <thead id=\"tabhead\" >\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >品种</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >品规</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:100px;\" >药品名称</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:100px;\" >分类</th>\n" +
                            // // "       <th style=\"text-align:center;vertical-align:middle;width: 50px;\" >品种/品规限制</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width: 145px;\" >规格</th>\n" +
                            // // "       <th style=\"text-align:center;vertical-align:middle;width: 65px;\" >价格(元）</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >单位</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width: 50px;\" >医保类别</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >基药</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >集采药</th>\n" +
                            // // "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >一致性评价</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >15版指导原则</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >院本部药</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:85px;\" >半年无采购记录</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:50px;\" >秦淮药</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width:85px;\" >半年无采购记录</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width: 100px;\" >药学建议</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;\" >备注</th>\n" +
                            // "       <th style=\"text-align:center;vertical-align:middle;width: 80px;\" >建议纳入目录的请打勾</th>\n" +
                            // "    </thead></table></div><div class='table-body'><table><tbody>";

                            "   <thead >\n" +
                            "    <tr style=\"font-weight: bold;\">\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">品种</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >品规</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:120px;\" rowspan=\"2\" >药品名称</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:120px;\" rowspan=\"2\" >分类</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" rowspan=\"2\" >规格</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >单位</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\" >医保类别</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:200px;\"colspan=\"4\" >推荐依据</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" colspan=\"2\">所在目录</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:200px;\" colspan=\"2\">半年无采购记录</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" rowspan=\"2\" >备注</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:200px;\"colspan=\"2\" >抗菌药物管理工作小组预选意见</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" rowspan=\"2\" >表决意见（同意保留请打勾）<input  onclick=\"toVoteSure('"+_this.xiangmuId+"')\"  type=\"checkbox\"></td>\n" +
                            "    </tr>\n" +
                            "    <tr style=\"font-weight: bold;\">\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >基药</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >集采药</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >一致性评价</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >15版指导原则</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >院本部</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" >秦淮</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" >院本部</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" >秦淮</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" >是否为前48个品种</td>\n" +
                            "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" >品规得票（总票数25）</td>\n" +

                            "    </tr></thead></table></div><div class='table-body'><table style=\"table-layout: fixed;\"><tbody>";
                        if(data.KangjunyaowuList.length > 0){
                            _this.show = true;
                            _this.kangjunyaowulist=data.KangjunyaowuList;

                            var PageInfo = data.PageInfo;
                            _this.pageIndex = PageInfo.pageIndex;
                            _this.recordCount = PageInfo.recordCount;
                            _this.pageCount = PageInfo.pageCount;

                            for (var i = 0; i < data.KangjunyaowuList.length; i++) {
                                var mmKangjunyaowu = data.KangjunyaowuList[i];

                                var mmPinzhong = mmKangjunyaowu.pinzhong;
                                var mmPinguiList = mmKangjunyaowu.pinguilist;
                                var mmPinzhongHebingshu = mmKangjunyaowu.pinzhonghebinghang;

                                for (var j = 0; j < mmPinguiList.length; j++) {
                                    var s=0;


                                    var mmPinguilist = mmPinguiList[j];
                                    var mmResult=mmPinguilist.result;
                                    var mmId=mmPinguilist.id;
                                    var mmPingui = mmPinguilist.pingui;
                                    var mmYaopinmingcheng = mmPinguilist.yaopinmingcheng;
                                    var mmXianzhishu = mmPinguilist.xianzhishu;
                                    var mmGuizebianhao = mmPinguilist.guizebianhao;
                                    var mmFenlei = mmPinguilist.fenlei;
                                    var mmXianzhitiaojian=mmPinguilist.xianzhitiaojian;
                                    var mmHebinghang=mmPinguilist.hebinghang;
                                    var mmGuige = mmPinguilist.guige;
                                    var mmDanwei = mmPinguilist.danwei;
                                    var mmJiage = mmPinguilist.jiage;
                                    var mmYibaoleibie = mmPinguilist.yibaoleibie;
                                    var mmGuojiajibenyaowu = mmPinguilist.guojiajibenyaowu;
                                    var mmJicaiyao = mmPinguilist.jicaiyao;
                                    var mmTongguopingjia = mmPinguilist.tongguopingjia;
                                    var mmZhidaoyuanze = mmPinguilist.zhidaoyuanze;
                                    var mmDongzongyao = mmPinguilist.dongzongyao;
                                    var mmDongzongjilu2="";
                                    if(mmPinguilist.dongzongjilu2!=undefined){
                                        var mmDongzongjilu2 = mmPinguilist.dongzongjilu2;
                                    }
                                    var mmQinhuaiyao = mmPinguilist.qinhuaiyao;

                                    var mmQinhuaijilu2="";
                                    if(mmPinguilist.qinhuaijilu2!=undefined){
                                        var mmQinhuaijilu2 = mmPinguilist.qinhuaijilu2;
                                    }
                                    var mmZhidaoyijian = mmPinguilist.zhidaoyijian;
                                    var mmBeizhu=mmPinguilist.beizhu;
                                    var mmPinzhongpaiming=mmPinguilist.pinzhongpaiming;
                                    var mmPinguipiaoshu=mmPinguilist.pinguipiaoshu;
                                    var mmHuanhangfu = "";
                                    var mmyijihe="";
                                    var mmyijihe2="";
                                    if(j==0 &&s==0){
                                        mmyijihe= "<td style='text-align:center;vertical-align:middle;width:50px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhong + "</td>";
                                        mmyijihe2= "<td style='text-align:center;vertical-align:middle;width: 100px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhongpaiming + "</td>";
                                        s= 1;
                                    }
                                    if(mmPinzhong%2==0){
                                        mmHtml +="<tr style='background-color: #f2f2f2'>"
                                    }else {
                                        mmHtml +="<tr>"
                                    }

                                    mmHtml +=mmyijihe;
                                    mmHtml += mmHuanhangfu + "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmPingui + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:120px;'>" + mmYaopinmingcheng + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:120px;'>" + mmFenlei + "</td>";
                                    // if(mmHebinghang!=null&&mmHebinghang!=0){
                                    //     mmHtml+= "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmHebinghang + "'>" + mmXianzhitiaojian + "</td>";
                                    // }
                                    // if(mmHebinghang==""){
                                    //     mmHtml += "<td style='text-align:center;vertical-align:middle;width: 50px;'>" + mmXianzhitiaojian + "</td>";
                                    // }

                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap; -moz-text-overflow: ellipsis;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                                    // mmHtml += "<td style='text-align:center;vertical-align:middle;width:65px;'>" + mmJiage + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmDanwei + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmYibaoleibie + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmGuojiajibenyaowu + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmJicaiyao + "</td>";
                                    // if(mmJicaiyao=="是"){
                                    //     mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>集采</td>";
                                    // }else {
                                    //     mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmJicaiyao + "</td>";
                                    // }

                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmTongguopingjia + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmZhidaoyuanze + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmDongzongyao + "</td>";

                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmQinhuaiyao + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmDongzongjilu2 + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmQinhuaijilu2 + "</td>";
                                    // mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmZhidaoyijian + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap; -moz-text-overflow: ellipsis;text-overflow: ellipsis; overflow: hidden; text-align: left;'><a title='" + mmBeizhu + "'>" + mmBeizhu + "</a></td>";
                                    // mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmPinzhongpaiming + "</td>";
                                    mmHtml +=mmyijihe2;
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmPinguipiaoshu + "</td>";

                                    var mmBtndiv="";
                                     if(_this.issubmited){
                                         if(mmResult==null||mmResult==0){
                                             mmBtndiv="<div  id='div_"+mmPinzhong+"_"+mmPingui+"' style=\"text-align:center;\"><input disabled onclick=\"toVote('"+mmId+"','"+mmPinzhong+"','"+mmPingui+"')\" id='checkbox_"+mmPinzhong+"_"+mmPingui+"' class='cbcss' type=\"checkbox\"></div>";
                                         }
                                         if(mmResult==1){
                                             mmBtndiv="<div id='div_"+mmPinzhong+"_"+mmPingui+"' style=\"text-align:center;\"><input disabled checked onclick=\"toVote('"+mmId+"','"+mmPinzhong+"','"+mmPingui+"')\" id='checkbox_"+mmPinzhong+"_"+mmPingui+"' class='cbcss' type=\"checkbox\"></div>";
                                         }
                                     }
                                     if(!_this.issubmited) {
                                         if(mmResult==null||mmResult==0){
                                             mmBtndiv="<div id='div_"+mmPinzhong+"_"+mmPingui+"' style=\"text-align:center;\"><input  onclick=\"toVote('"+mmId+"','"+mmPinzhong+"','"+mmPingui+"')\" id='checkbox_"+mmPinzhong+"_"+mmPingui+"' class='cbcss' type=\"checkbox\"></div>";
                                         }
                                         if(mmResult==1){
                                             mmBtndiv="<div id='div_"+mmPinzhong+"_"+mmPingui+"' style=\"text-align:center;\"><input checked  onclick=\"toVote('"+mmId+"','"+mmPinzhong+"','"+mmPingui+"')\" id='checkbox_"+mmPinzhong+"_"+mmPingui+"'  class='cbcss' type=\"checkbox\"></div>";
                                         }
                                     }



                                    mmHtml +="<td style='text-align:center;vertical-align:middle;width:100px;height: 100%'" + mmPinzhongHebingshu + ">" + mmBtndiv + "</td>";


                                    mmHtml += "</tr>";

                                }
                            }

                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</tbody></table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        getkangjunResultCount:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/kangjunyaowujieguo/getKangJunResultCount', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.pinzhongshu=data.pinzhongshu;
                        _this.pinguishu=data.pinguishu;
                        _this.jicaiyaoshu=data.jicaiyaoshu;
                        _this.fenleishu=data.fenleishu;
                        _this.shengyujicaiyaoshu=data.shengyujicaiyaoshu;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        checkIsSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.issubmited=true;
                        }
                        _this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsAllSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsAllSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.isallsubmited=true;
                        }
                        //_this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        tosubmit:function (){
            var _this = this;
            layer.confirm("是否确认提交？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});
                $.post('/renyuanfenpei/submit', {
                    xiangmuid :_this.xiangmuId,
                    userid :_this.userId,
                    rdm : Math.random()
                },function(ppData) {
                    layer.closeAll("loading");
                    if(ppData != null){
                        if(ppData.result == "1"){
                            _this.issubmited=true;
                            layer.alert("提交成功");
                            _this.findBiaojuelist();
                        }else{
                            layer.alert(ppData.message);
                        }
                    }
                },"json");
            })




        },


        /* toVote:function (ppId,ppIstongyi) {

             var _this = this;
             layer.open({type: 3});
             $.post('/jieguo/toupiao', {
                 id: ppId,
                 userid: _this.userId,
                 result: ppIstongyi,
                 rdm: Math.random()
             }, function (ppData) {
                 layer.closeAll("loading");
                 if (ppData != null) {
                     if (ppData.result == "1") {
                         _this.getYinjinResultCount();
                         if (ppIstongyi == 1) {
                             $("#jieguo" + ppId).html("<span style=\"color:#008000\">同意</span>");
                         }
                         if (ppIstongyi == 0) {
                             $("#jieguo" + ppId).html("<span style=\"color:#ff0000\">不同意</span>");
                         }
                     } else {
                         layer.alert(ppData.message);
                     }
                 }
             }, "json");
         },*/



        /**
         * 合并单元格(如果结束行传0代表合并所有行)
         * @param table1    表格的ID
         * @param startRow  起始行
         * @param endRow    结束行
         * @param col   合并的列号，对第几列进行合并(从0开始)。第一行从0开始
         */
        /* mergeCell: function (tableId, startRow, endRow, col) {
             alert(startRow)
             var tb = document.getElementById(tableId);
             if (col >= tb.rows[0].cells.length) {
                 return;
             }
             if (col == 0) { endRow = tb.rows.length-1; }
             for (var i = startRow; i < endRow; i++) {
                 if (tb.rows[startRow].cells[col].innerHTML == tb.rows[i + 1].cells[0].innerHTML) {
                     tb.rows[i + 1].removeChild(tb.rows[i + 1].cells[0]);
                     tb.rows[startRow].cells[col].rowSpan = (tb.rows[startRow].cells[col].rowSpan | 0) + 1;
                     if (i == endRow - 1 && startRow != endRow) {
                         mc(tableId, startRow, endRow, col + 1);
                     }
                 } else {
                     this.mergeCell(tableId, startRow, i + 0, col + 1);
                     startRow = i + 1;
                 }
             }
          },*/

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },
    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.findBiaojuelist();
        }
    }
})